package com.jieshuibao.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.jieshuibao.mapper.PraiseMapper;
import com.jieshuibao.model.db.Praise;
import com.jieshuibao.model.db.PraiseExample;
import com.jieshuibao.model.db.PraiseExample.Criteria;

@Service
public class PraiseService{
	
	@Resource
	private PraiseMapper praiseMapper;
	
	public void addPraise(Praise praise) {
		praiseMapper.insertSelective(praise);
	}
	
	public void delPraiseByUuid(String uuid) {
		praiseMapper.deleteByPrimaryKey(uuid);
	}
	
	public void updatePraise(Praise praise) {
		praiseMapper.updateByPrimaryKeySelective(praise);
	}
	
	public Praise getPraiseByUuid(String uuid) {
		return praiseMapper.selectByPrimaryKey(uuid);
	}
	
	public List<Praise> getPagePraise(PraiseExample praiseExample) {
		return praiseMapper.selectPage(praiseExample);
	}
	
	public int countPraise(PraiseExample praiseExample) {
		return praiseMapper.countByExample(praiseExample);
	}
	
	public List<Praise> getPraises(PraiseExample praiseExample){
		return praiseMapper.selectByExample(praiseExample);
	}
	
	public Praise getPraise(String userId,String uuid){
		PraiseExample praiseExample = new PraiseExample();
		Criteria createCriteria = praiseExample.createCriteria();
		createCriteria.andUserIdEqualTo(userId);
		createCriteria.andProductIdEqualTo(uuid);
		createCriteria.andTypeEqualTo("0");//0  答案的点赞
		List<Praise> list = praiseMapper.selectByExample(praiseExample);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
		
	}
}
